import vueRouter, { NavigationFailure, RouteRecordRaw, createRouter, createWebHistory } from 'vue-router'

const photo = {
  path: '/sys',
  name: '系统',
  meta: {
    title: '系统'
  },
  component: () => import('@/layout/layout.vue'),
  redirect: '/wall',
  children: [
    {
      path: '/wall',
      name: '照片管理',
      icon: 'DashboardOutlined',
      component: () => import('@/pages/photo.vue')
    },
    {
      path: '/category',
      name: '分类管理',
      icon: 'DashboardOutlined',
      component: () => import('@/pages/category.vue')
    }
  ]
}

const _routes = [photo] as any

if (_routes[0].link) {
  window.open(_routes[0].path)
}

const redirectRoutes = {
  path: '/',
  name: '',
  meta: {
    title: ''
  },
  redirect: _routes[0].redirect
}

export const routes: Array<ROUTER.RoutesProps> = [redirectRoutes, ..._routes]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: routes.map(item => {
    const _item = item.link
      ? {
          ...item,
          path: '/' + item.path
        }
      : item
    return _item
  })
})

export default router
